#ifndef CONNECTMYSQLDIALOG_H
#define CONNECTMYSQLDIALOG_H

#include <QDialog>
#include <QDialog>
#include <QLabel>
#include <QLineEdit>
#include <QPushButton>
#include <QComboBox>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QtSql>
#include <QSqlDatabase>
#include <QSqlQuery>
#include <QMessageBox>
#include <QStandardItemModel>
#include <QStandardItem>
#include <QTreeWidgetItem>
#include "src/util/appevent.h"

namespace Ui {
class ConnectMySQLDialog;
}

class ConnectMySQLDialog : public QDialog
{
    Q_OBJECT

public:
    explicit ConnectMySQLDialog(QWidget *parent = nullptr);
    ~ConnectMySQLDialog();
public:
    void iniDialog();
    bool testConnection(QString host,int port,QString user,QString password,QString database);
    QList<QStandardItem*> readDatabase();
    QTreeWidgetItem* readDBContext();
signals:
    void sigUpdateDBTreeView(const QString &root,QList<QStandardItem*> context);
    void sigUpdateDBTreeWidget(const QString &root,QTreeWidgetItem *context);
private:
    QSqlDatabase DBMySQL;

    QString mysqlHost;
    int mysqlPort;
    QString mysqlUser;
    QString mysqlPassword;
    QString mysqlDatabase;

    QLineEdit *editHost;
    QLineEdit *editPort;
    QLineEdit *editUser;
    QLineEdit *editPassword;
    QLineEdit *editDatabase;

    QMap<QString,QString> FLayerMap;
    QVector<QMap<QString,QString>> FLayersList;

private slots:
    void on_btnOK_clicked();
    void on_btnCancel_clicked();

private:
    Ui::ConnectMySQLDialog *ui;
};

#endif // CONNECTMYSQLDIALOG_H
